package com.alist;

import java.util.*;

public class AList {

    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<String>();
        //断点跟踪add
        arrayList.add("100");
        arrayList.add("200");
        arrayList.add("300");
        arrayList.add("400");

//        //断点跟踪get
//        for (int i = 0; i <arrayList.size() ; i++) {
//            arrayList.get(i);
//
//        }

//        //断点跟踪remove
//        arrayList.remove(1);
//        //arrayList.remove("100");//和上面逻辑一样remove
//        System.out.println(arrayList);
        
        //断点跟踪set
        arrayList.set(1, "2000000");
        System.out.println(arrayList);
        
        //断点跟踪clear
        arrayList.clear();
        System.out.println(arrayList);
//
//
        Integer value = null;
        Iterator iter = arrayList.iterator();
        while (iter.hasNext()) {
            value = (Integer) iter.next();
        }
        
    }
    
    //ArrayList
    public static void method_1() {
        Collection<String> col1 = new ArrayList<String>();
        // 向集合中添加元素
        col1.add("hello");
        col1.add("world");
        col1.add("java");
        // 把集合转换成数组
        Object[] objects = col1.toArray();
        // 遍历数组
        for (int x = 0; x < objects.length; x++) {
            System.out.println(objects[x]);             // 获取数组元素并且进行输出
        }
        
    }
    
    //LinkedList
    public static void method_2() {
        Collection<String> col1 = new LinkedList<String>();
        // 向集合中添加元素
        col1.add("hello");
        col1.add("world");
        col1.add("java");
        // 把集合转换成数组
        Object[] objects = col1.toArray();
        // 遍历数组
        for (int x = 0; x < objects.length; x++) {
            System.out.println(objects[x]);             // 获取数组元素并且进行输出
        }
    }
    
    //HashSet
    public static void method_3() {
        HashSet<String> strs = new HashSet<String>();
        strs.add("1");
        Collection<String> col1 = new ArrayList<String>(strs);
        System.out.println(col1);
        
    }
    
}
